package config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.Yaml;

import config.Config.ServiceMode;


public class Configure {
	static Config conf = new Config();

	public static void init(String file) {
		FileInputStream input;
		try {
			input = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		org.yaml.snakeyaml.constructor.Constructor constructor = new org.yaml.snakeyaml.constructor.Constructor(
				Config.class);
		Yaml yaml = new Yaml(new Loader(constructor));
		conf = (Config) yaml.load(input);
	}

	public static String getRpcAddress(){
		return conf.rpcAddress;
	}
	
	public static short getRpcPort() {
		return conf.rpcPort;
	}
	
	public static long getRpcTimeout() {
		return conf.rpcTimeOut;
	}
	
	public static String getListenAddress() {
		return conf.listenAddress;
	}
	
	public static int getListenPort() {
		return conf.listenPort;
	}

	public static long getConnectionMaxIdleTime() {
		return conf.connectionMaxIdleTime;
	}
	
	public static ServiceMode getServiceMode() {
		return conf.mode;
	}
	
	public static DBOption[] getDBOptions() {
		return conf.dbs;
	}
}
